package cn.edu.nju.software.greencreditsystem.DAOImpl;

import cn.edu.nju.software.greencreditsystem.DAO.BankLoginDAO;
import cn.edu.nju.software.greencreditsystem.domain.BankLogin;
import cn.edu.nju.software.greencreditsystem.factory.SessionPool;
import java.util.List;
import org.hibernate.Session;

/**
 * 作者：何启睿
 * 创建时间：2011-8-16
 * 类描述：BankLogin类DAO接口
 */
public class BankLoginDAOImpl implements BankLoginDAO
{

    @Override
    public boolean save(BankLogin bl)
    {
        boolean result = false;
        Session s = SessionPool.getSession();
        s.beginTransaction();
        try
        {
            s.save(bl);
            s.getTransaction().commit();
            result = true;
        }catch(Exception ex)
        {
            ex.printStackTrace();
            s.getTransaction().rollback();
        }finally
        {
            s.close();
        }
        
        return result;
    }
    
    @Override
    public List<BankLogin> getAll()
    {
        List<BankLogin> result = null;
        Session s = SessionPool.getSession();
        s.beginTransaction();
        try
        {
            result = s.createQuery("from BankLogin").list();
            s.getTransaction().commit();
        }catch(Exception ex)
        {
            ex.printStackTrace();
            s.getTransaction().rollback();
        }finally
        {
            s.close();
        }
        
        return result;
    }
    
}
